package io.renren.modules.generator.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.generator.entity.StudentEntity;
import io.renren.modules.generator.service.StudentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

@RestController
@RequestMapping("generator/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    //列表
    @RequestMapping("/list")
    @RequiresPermissions("generator:student:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = studentService.queryPage(params);
        return R.ok().put("page",page);
    }

    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:student:info")
    public R info(@PathVariable("id") Integer id){
        StudentEntity student = studentService.selectById(id);
        return R.ok().put("student", student);
    }

    //添加
    @RequestMapping("/save")
    @RequiresPermissions("generator:student:save")
    public R save(@RequestBody StudentEntity student){
        studentService.insert(student);
        return R.ok();
    }

    //修改
    @RequestMapping("/update")
    @RequiresPermissions("generator:student:update")
    public R update(@RequestBody StudentEntity student){
        studentService.updateById(student);
        return R.ok();
    }



    //删除
    @RequestMapping("/delete")
    @RequiresPermissions("generator:student:delete")
    public R delete(@RequestBody Integer id){
        studentService.deleteBatchIds(Arrays.asList(id));
        return R.ok();
    }


}
